<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>articleManger</title>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/jquery-easyui-1.3.3/themes/icon.css">
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/kindeditor-4.1.10/themes/default/default.css"/>
    <script charset="utf-8" src="${pageContext.request.contextPath}/kindeditor-4.1.10/kindeditor-all.js"></script>
    <script charset="utf-8" src="${pageContext.request.contextPath}/kindeditor-4.1.10/lang/zh_CN.js"></script>

</head>
<body style="margin:1px;" id="ff">
<table id="dg"  class="easyui-datagrid" pagination="true"
       rownumbers="false" fit="true"
       url="${pageContext.request.contextPath}/achievement/search" toolbar="#tb">
    <thead data-options="frozen:false">
    <tr>
        <th field="cb" checkbox="true" align="center"></th>
        <th field="id" width="100%" align="center" hidden="true">编号</th>
        <th field="technicalNo" width="100" align="center">技术编号</th>
        <th field="name" width="300" align="center">技术名称</th>
        <th field="createTime" width="150" align="center">创建时间</th>
        <th field="createUserid" width="100" align="center">创建人id</th>
        <th field="range" width="200" align="center">技术应用范围</th>
        <th field="price" width="100" align="center">合作价格</th>
        <th field="payform" width="100" align="center">交付形式</th>
        <th field="patent" width="100" align="center">专利</th>
        <!-- <th field="background" width="100" align="center" formatter="showBackground">技术背景</th>
        <th field="introduction" width="100" align="center" formatter="showBackground">技术介绍</th>
        <th field="advantage" width="100" align="center" formatter="showBackground">技术优势</th>
        <th field="effect" width="100" align="center" formatter="showBackground">应用影响</th> -->
        <th field="status" width="100%" align="center" formatter="getStatus">状态</th>
        <th field="content" width="100%" align="center"
            formatter="formatHref">操作
        </th>
    </tr>
    </thead>
</table>

<div id="tb">
    <div>
        <a href="javascript:refuseAchieve()" class="easyui-linkbutton"
           iconCls="icon-cancel" plain="true">驳回</a>
        <a
            href="javascript:agreeAchieve()"
            class="easyui-linkbutton" iconCls="icon-ok" plain="true">通过</a> 
        <a
            href="javascript:deleteAchieve()" class="easyui-linkbutton"
            iconCls="icon-remove" plain="true">删除</a> 
    </div>
</div>

<div id="dlg" class="easyui-dialog"
     style="width: 850px;height:555px;padding: 10px 20px; position: relative; z-index:1000;"
     closed="true" buttons="#dlg-buttons">
    <form id="fm" method="post">
        <table cellspacing="8px">
            <tr>
                <td>标题：</td>
                <td><input type="text" id="title" name="title"
                           class="easyui-validatebox" required="true"/>&nbsp;<font
                        color="red">*</font>
                    <input id="articleIdfm" name="id" type="hidden" value="0">
                </td>
            </tr>
            <tr>
                <td>详细内容</td>
                <td>
                    <textarea id="editor"
                              style="width:800px;height:400px;visibility:hidden;"></textarea>
                </td>
            </tr>
        </table>
    </form>
</div>

<div id="dlg-buttons">
    <a href="javascript:saveArticle()" class="easyui-linkbutton"
       iconCls="icon-ok">保存</a> <a href="javascript:closeArticleDialog()"
                                   class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>


<script type="text/javascript">
    var url = "/news/insert";
    var method;
    $(function () {
        //详情编辑器
        KindEditor.ready(function (K) {
            this.editor
                = K.create('textarea[id="editor"]', {
                items: ['source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
                    'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
                    'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
                    'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
                    'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
                    'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|','multiimage',
                    'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
                    'anchor', 'link', 'unlink'],
                uploadJson: '${pageContext.request.contextPath}/uploadImages',
                filePostName: 'file',
                fileManagerJson: '/images',
                allowFileManager: true
            });
        });
    });

    function openArticleAddDialog() {
        editor.html('请输入内容');
        $("#dlg").dialog("open").dialog("setTitle", "添加文本信息");
        method = "POST";
        url = "/news/insert";
    }

    function saveArticle() {
        var title = $("#title").val();
        var content = editor.html();
        var id = $("#articleIdfm").val();
        var data = {"id":id,"title": title, "content": content};
        $.ajax({
            type: method,//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: url,//url
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(data),
            success: function (result) {
                console.log(result);//打印服务端返回的数据
                if (result.resultCode == 200) {
                    $.messager.alert("系统提示", "保存成功");
                    $("#dlg").dialog("close");
                    $("#dg").datagrid("reload");
                    resetValue();
                }
                else {
                    $.messager.alert("系统提示", "操作失败");
                    $("#dlg").dialog("close");
                    resetValue();
                }
                ;
            },
            error: function () {
                $.messager.alert("系统提示", "操作失败");
            }
        });
    }

    function openArticleModifyDialog() {
        var selectedRows = $("#dg").datagrid('getSelections');
        if (selectedRows.length != 1) {
            $.messager.alert("系统提示", "请选择一条要编辑的数据！");
            return;
        }
        var row = selectedRows[0];
        $("#dlg").dialog("open").dialog("setTitle", "修改信息");
        $('#fm').form('load', row);
        editor.html(row.content);
        method = "POST";
        $("#articleIdfm").val(row.id);
        url="/news/update";
    }

    function formatHref(val, row) {
        return "<a href='${pageContext.request.contextPath}/portal/techdetail.html?id=" + row.id + "' target='_blank'>查看详情</a>";
    }
    
    function getStatus(val,row){
        if(val==null){
            var html1=`<span style="color: blue;">未审核</span>`;
            return html1;
        }
        
        if(val==0){
           var html1=`<span style="color: blue;">未审核</span>`;
           return html1;
        }
        
        if(val==1){
            var html2=`<span style="color: green;">通过</span>`;
            return html2;
        }
        
        if(val==2){
            var html3=`<span style="color: red;">驳回</span>`;
            return html3;
        }
    }

    function resetValue() {
        $("#title").val("");
        $("#addName").val("");
        $("#container").val("");
        editor.html();
    }

    function closeArticleDialog() {
        $("#dlg").dialog("close");
        resetValue();
    }
    
    /*删除*/
    function deleteAchieve() {
        var selectedRows = $("#dg").datagrid('getSelections');
        if (selectedRows.length == 0) {
            $.messager.alert("系统提示", "请选择！");
            return;
        }
        var strIds = [];
        for (var i = 0; i < selectedRows.length; i++) {
            strIds.push(selectedRows[i].id);
        }
        var ids = strIds.join(",");
        $.messager.confirm("系统提示", "您确认要删除？", function (r) {
            if (r) {
                $.ajax({
                    type: "GET",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/achievement/delete/" + ids,//url
                    data: {},
                    success: function (result) {
                        console.log(result);//打印服务端返回的数据
                        if (result.resultCode == 200) {
                            $.messager.alert(
                                    "系统提示",
                                    "成功删除！");
                            $("#dg").datagrid(
                                    "reload");
                        }
                        else {
                            $.messager.alert(
                                    "系统提示",
                                    "数据删除失败！");
                        }
                    },
                    error: function () {
                        $.messager.alert("ERROR！");
                    }
                });
            }
        });
    }
   
    /*驳回*/
    function refuseAchieve(){
        var selectedRows = $("#dg").datagrid('getSelections');
        if (selectedRows.length == 0) {
            $.messager.alert("系统提示", "未选择！");
            return;
        }
        var id=selectedRows[0].id;//商品id
        var status=selectedRows[0].status;
        if(status==2){
            $.messager.alert("系统提示", "已驳回！");
            return;
        }
        
        var dt={"id":id,"status":2};
        $.messager.confirm("系统提示", "您确认要驳回？", function (r) {
            if (r) {
                $.ajax({
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/achievement/update",//url
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify(dt),
                    success: function (result) {
                        console.log(result);//打印服务端返回的数据
                        if (result.resultCode == 200) {
                            $("#dg").datagrid("reload");
                        }
                        else {
                            $.messager.alert(
                                    "系统提示",
                                    "驳回失败！");
                        }
                    },
                    error: function () {
                        $.messager.alert("ERROR！");
                    }
                });
            }
        });
    }

    /*通过*/
    function agreeAchieve(){
        var selectedRows = $("#dg").datagrid('getSelections');
        if (selectedRows.length == 0) {
            $.messager.alert("系统提示", "请选择！");
            return;
        }
        var id=selectedRows[0].id;//商品id
        var status=selectedRows[0].status;
        if(status==1){
            $.messager.alert("系统提示", "已审核！");
            return;
        }
        var dt={"id":id,"status":1};
        $.messager.confirm("系统提示", "您确认要审核通过？", function (r) {
            if (r) {
                $.ajax({
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/achievement/update",//url
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify(dt),
                    success: function (result) {
                        console.log(result);//打印服务端返回的数据
                        if (result.resultCode == 200) {
                            $("#dg").datagrid("reload");
                        }
                        else {
                            $.messager.alert(
                                    "系统提示",
                                    "审核通过失败！");
                        }
                    },
                    error: function () {
                        $.messager.alert("ERROR！");
                    }
                });
            }
        });
    }
</script>
</body>
</html>